package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.stelesoul.SteleSoulUserData;
import com.yanqu.road.entity.activity.stelesoul.config.SteleSoulConfig;
import com.yanqu.road.entity.config.goods.OpenGoodsBagResult;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eMailType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.logic.bussiness.activity.SteleSoulBusiness;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.stelesoul.SteleSoulModule;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.stelesoul.SteleSoulMgr;
import com.yanqu.road.server.manger.config.GoodsBagMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.ArrayList;
import java.util.List;

public class SteleSoulRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        ActivityInfo activityInfo = SteleSoulMgr.getActivityInfo();
        SteleSoulConfig config = SteleSoulMgr.getSteleSoulConfig();
        if (activityInfo != null && config != null) {
            long recycleTime = activityInfo.getEndShowTime() * 1000L + 300 * 1000;
            // 回收道具
            List<String> energyList = new ArrayList<>();
            // 抽奖道具 魂元
            energyList.add(String.valueOf(config.getConsumeItemId()));
            energyList.add(activityInfo.getActivityName());
            ActivityItemRecycleMgr.addRecycleItemData(config.getConsumeItemId(), activityType, 2, recycleTime, energyList);
        }
    }

    @Override
    protected void initActivityType() {
        this.activityType = eActivityType.SteleSoul.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        int itemId = data.getItemId();
        UserBagItem userBagItem = getUserBagItem(userId, itemId);
        if(userBagItem == null){
            return;
        }
        long bagCount = userBagItem.getNum();
        if(bagCount <= 0){
            return;
        }
        removeItem(userBagItem);

    }

    @Override
    public boolean isActivityRunning() {
        ActivityInfo activityInfo = SteleSoulMgr.getActivityInfo();
        if(activityInfo == null || SteleSoulMgr.getSteleSoulConfig() == null){
            SteleSoulMgr.getLogger().error("SteleSoul Recycle Fail, Because ActivityInfo is null");
            return false;
        }
        return ActivityMgr.activityInTime(activityInfo);
    }

//    private void recycleItem(long userId, ActivityItemRecycleData data) {
//        Property property = new Property();
//        int itemId = data.getItemId();
//        UserBagItem userBagItem = getUserBagItem(userId, itemId);
//        if (userBagItem != null && userBagItem.getNum() > 0) {
//            for (int i = 0; i < userBagItem.getNum(); i++) {
//                OpenGoodsBagResult openGoodsBagResult = GoodsBagMgr.getRandomGoods(userBagItem.getGoodsId());
//                property.addProperty(openGoodsBagResult.getReward());
//            }
//            removeItem(userBagItem);
//        }
//        if (property.getGoods().size() > 0) {
//            String language = UserMgr.getLanguage(userId);
//            String mailTitle = MultipleLanguageMgr.getContent(MailManager.STONESOUL_MAIL_TITLE, language);
//            String mailContent = MultipleLanguageMgr.getContent(MailManager.STONESOUL_MAIL_CONTENT, language);
//            MailManager.sendMail(userId, eMailType.SYSTEM.getValue(), PropertyHelper.parsePropertyToString(property), mailContent,mailTitle);
//        }
//    }
}
